#pragma once

#include <iostream>
#include <string>
#include <fstream> // c++ 文件流
#include <vector>
#include <boost/algorithm/string.hpp>
#include "Cppjieba/Jieba.hpp"

namespace ns_util
{
	class FileUtil
	{
		public:
			static bool ReadFile(const std::string& file_path, std::string* out)
			{
				std::ifstream in(file_path, std::ios::in);
				if (!in.is_open()) 
				{
					std::cerr << "open file " << file_path << " error" << std:: endl;
					return false;
				}

				// 已经打开文件
				// 通过 getline 按行读取
				// 拓展：getline 返回值是一个流类型的引用
				std::string line;
				while (std::getline(in, line))
				{
					*out += line;
				}
				in.close();
				return true;
			}
	};

	class StringUtil
	{
		public:
			// 需要被切分原字符串 放切分后结果的数组 分隔符
			static void Split(const std::string& target, std::vector<std::string>* out, const std::string& sep)
			{
				// boost split 
				 boost::split(*out, target, boost::is_any_of(sep), boost::token_compress_on);
			}
	};

	const char* const DICT_PATH = "./dict/jieba.dict.utf8";
	const char* const HMM_PATH = "./dict/hmm_model.utf8";
	const char* const USER_DICT_PATH = "./dict/user.dict.utf8";
	const char* const IDF_PATH = "./dict/idf.utf8";
	const char* const STOP_WORD_PATH = "./dict/stop_words.utf8";
	class JiebaUtil
	{
		private:
			static cppjieba::Jieba jieba; 
		public:
			static void CutString(const std::string& src, std::vector<std::string>* out)
			{
				jieba.CutForSearch(src, *out);
			}
	};

	cppjieba::Jieba JiebaUtil::jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH);
}